package com.xiaoyu.lanling.feature.chat.model.message

import com.xiaoyu.base.data.UserData
import com.xiaoyu.im.datamodel.AppMessage
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_01_SYSTEM
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_1000_TEXT
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_1001_IMAGE
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_1002_AUDIO
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_1003_GIFT
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_1004_CALL
import com.xiaoyu.lanling.feature.chat.model.message.MessageType.TYPE_1005_VIDEO

object MessageFactory {

    fun create(message: AppMessage): ChatMessageBaseItem {
        return if (!UserData.getInstance().isSelf(message.senderUid)) {
            createReceive(message)
        } else {
            createSend(message)
        }
    }

    private fun createSend(message: AppMessage): ChatMessageBaseItem {
        return when (message.payload.messageType) {
            TYPE_01_SYSTEM -> ChatMessageSystemItem(message)
            TYPE_1000_TEXT -> ChatMessageSendTextItem(message)
            TYPE_1001_IMAGE -> ChatMessageSendImageItem(message)
            TYPE_1002_AUDIO -> ChatMessageSendAudioItem(message)
            TYPE_1003_GIFT -> ChatMessageSendGiftItem(message)
            TYPE_1004_CALL -> ChatMessageSendCallItem(message)
            TYPE_1005_VIDEO -> ChatMessageSendVideoItem(message)
            else -> ChatMessageUnknownItem(message)
        }
    }

    private fun createReceive(message: AppMessage): ChatMessageBaseItem {
        return when (message.payload.messageType) {
            TYPE_01_SYSTEM -> ChatMessageSystemItem(message)
            TYPE_1000_TEXT -> ChatMessageReceiveTextItem(message)
            TYPE_1001_IMAGE -> ChatMessageReceiveImageItem(message)
            TYPE_1002_AUDIO -> ChatMessageReceiveAudioItem(message)
            TYPE_1003_GIFT -> ChatMessageReceiveGiftItem(message)
            TYPE_1004_CALL -> ChatMessageReceiveCallItem(message)
            TYPE_1005_VIDEO -> ChatMessageReceiveVideoItem(message)
            else -> ChatMessageUnknownItem(message)
        }
    }
}